package com.itheima.userconsumer.rabbitmq;
import com.itheima.userconsumer.dao.MessageMapper;
import com.itheima.userdemo.domain.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;

@Component
public class UserRabbitMq {
    @Autowired
    private MessageMapper messageMapper;
    @RabbitListener(queues = "UserQueue")
    public void ListenerQueue(org.springframework.amqp.core.Message message) throws IOException, ClassNotFoundException {
        ByteArrayInputStream bais = new ByteArrayInputStream(message.getBody());
        ObjectInputStream oii = new ObjectInputStream(bais);
        Message message1= (Message)oii.readObject();
        messageMapper.addMessage(message1);
    }
    @RabbitListener(queues = "DelayQueue_dle")
    public void ListenerQueue1(org.springframework.amqp.core.Message message) throws IOException, ClassNotFoundException {
        System.out.println(message);
    }
}
